
#ifdef _UNIT_TEST

#include "Render.h"
#include <cppunit/extensions/HelperMacros.h>


class TestWorldModel : public CppUnit::TestFixture
{
	CPPUNIT_TEST_SUITE( TestWorldModel );
		CPPUNIT_TEST( test_camera );
		CPPUNIT_TEST( test_clip );
	CPPUNIT_TEST_SUITE_END();

	WorldModel3D m_World;
public:

	void setUp() 
	{
		//test construction
		m_World.camera_data.clip.set_data_by_fov(90,90,10,300);
	}
	void tearDown() 
	{
		//test destruction
	}

	void test_camera()
	{
		Matrix3D matrix = m_World.camera_data.camera.get_forward_matrix() * m_World.camera_data.camera.get_backward_matrix();
		CPPUNIT_ASSERT_MESSAGE("World camera matrix error",matrix == Matrix3D::I() );
	}

	void test_clip()
	{
		Matrix3D matrix = m_World.camera_data.clip.get_forward_matrix() * m_World.camera_data.clip.get_backward_matrix();
		CPPUNIT_ASSERT_MESSAGE("World clip matrix error",matrix == Matrix3D::I() );
		{
			Point3D ptn = build_point_3D(1,1,0);
			Point3D ptf = build_point_3D(1,1,1);
			Point3D pt1 = m_World.camera_data.clip.get_backward_matrix() * ptn;
			pt1 /= pt1.h();
			Point3D pt2 = m_World.camera_data.clip.get_backward_matrix() * ptf;
			pt2 /= pt2.h();
			CPPUNIT_ASSERT( is_equal(pt1.x(),10) );
			CPPUNIT_ASSERT( is_equal(pt2.x(),300) );
			CPPUNIT_ASSERT( is_equal(pt1.y(),10) );
			CPPUNIT_ASSERT( is_equal(pt2.y(),300) );
			CPPUNIT_ASSERT( is_equal(pt1.z(),10) );
			CPPUNIT_ASSERT( is_equal(pt2.z(),300) );
		}

		{
			Point3D ptn = build_point_3D(10,10,10);
			Point3D ptf = build_point_3D(300,300,300);
			Point3D pt1 = m_World.camera_data.clip.get_forward_matrix() * ptn;
			pt1 /= pt1.h();
			Point3D pt2 = m_World.camera_data.clip.get_forward_matrix() * ptf;
			pt2 /= pt2.h();
			CPPUNIT_ASSERT( is_equal(pt1.x(),1) );
			CPPUNIT_ASSERT( is_equal(pt2.x(),1) );
			CPPUNIT_ASSERT( is_equal(pt1.y(),1) );
			CPPUNIT_ASSERT( is_equal(pt2.y(),1) );
			CPPUNIT_ASSERT( is_equal(pt1.z(),0) );
			CPPUNIT_ASSERT( is_equal(pt2.z(),1) );
		}
	}

};

CPPUNIT_TEST_SUITE_REGISTRATION( TestWorldModel );


#endif